<template>
    <el-main v-loading="loading">
        <el-row :gutter="20" class="margin_bottom_30">
            <el-col :span="4">
                <el-input placeholder="输入用户昵称" size="small" v-model="filterData.memberNickName"></el-input>
            </el-col>
            <el-col :span="4">
                <el-select
                    v-model="filterData.medalType"
                    prop="campaignState"
                    placeholder="请选择勋章类型"
                    size="small"
                    style="width:100%"
                    @change="checkMedalType">
                    <el-option
                        v-for="item in medalTypeList"
                        :key="item.labelId"
                        :label="item.labelText"
                        :value="item.labelId">
                    </el-option>
                </el-select>
            </el-col>
            <el-col :span="4" :offset="1">
                <el-button type="primary" size="small" @click="search">搜 索</el-button>
                <el-button size="small" @click="resetQuery">重 置</el-button>
            </el-col>
        </el-row>
        <el-table
            :data="dataList"
            border
            :row-key="row => row.memberMedalRecordsUid"
            height="640"
            :header-cell-style="{background:'#afafaf',color:'#606266'}"
            ref="multipleTable"
            @selection-change="handleSelectionChange">
            <el-table-column align="center" type="selection" reserve-selection width="40"></el-table-column>
            <el-table-column align="center" width="100" label="用户昵称">
                <template slot-scope="scope">
                    <p>{{scope.row.wechatNickName ? $util.decode(scope.row.wechatNickName) : '待录入'}}</p>
                </template>
            </el-table-column>
            <el-table-column width="150" label="城市" align="center">
                <template slot-scope="scope">
                    <p>{{scope.row.wechatCity || '待录入'}}</p>
                </template>
            </el-table-column>
            <el-table-column align="center" width="150" label="联系方式">
                <template slot-scope="scope">
                    <p>{{scope.row.wechatMobile || '待录入'}}</p>
                </template>
            </el-table-column>
            <el-table-column width="220" label="勋章信息">
                <template slot-scope="scope">
                    <p>类型：<span>{{getMedalType(scope.row.medalInfoModel.medalType)}}</span></p>
                    <p>名称：<el-tooltip :content="scope.row.medalInfoModel.medalName">
                                <span>{{scope.row.medalInfoModel.medalName | controlLength}}</span>
                            </el-tooltip>
                    </p>
                    <p>描述：<el-tooltip :content="scope.row.medalInfoModel.medalDesc">
                                <span>{{scope.row.medalInfoModel.medalDesc | controlLength}}</span>
                            </el-tooltip>
                    </p>
                </template>
            </el-table-column>
            <el-table-column align="center" width="100" label="勋章图像">
                <template slot-scope="scope">
				    <img v-image-preview :src="scope.row.medalInfoModel.medalImageUrlOn" width="60" />
			    </template>
            </el-table-column>
            <el-table-column prop="medalGetTime" align="center" width="160" label="获取时间"></el-table-column>
        </el-table>

        <el-row class="footer">
            <el-col :span="12">
				<el-checkbox
                    v-model="checkAll"
                    :disabled="!dataList.length"
                    @change="handleCheckAllChange">全选
                </el-checkbox>
			</el-col>
			<el-col :span="12">
				<el-pagination
                    @current-change="handleCurrentChange"
                    :current-page="page"
                    :page-size="10"
                    background
                    :disabled="!dataList.length"
                    :total="count"
                    class="text_align_right"
                    layout="total, prev, pager, next, jumper">
                </el-pagination>
			</el-col>
		</el-row>
    </el-main>
</template>
<script>
    import { medalRecordList } from "@/api/table";
    import utils from '@/utils/utils';

    export default {
        name: "MEDAL_RECORD_LIST",
        filters: {
            controlLength: curStr => utils.controlLength(curStr, 10),
        },
        data() {
            return {
                count: 0,
                checkAll: false, // 全选
                medalTypeList: [{
					labelId: 1,
					labelText: '成就勋章'
				}, {
					labelId: 2,
					labelText: '特殊勋章'
				}],
                dataList: [],
                loading: false,
                page: 1,
                filterData: {},
            }
        },
        components: {},
        mounted() {
            this.getData();
        },
        methods: {
            // 获取类型
            getMedalType(id) {
                const info = this.medalTypeList.find(item => item.labelId === id) || {};
                return info.labelText || ''
            },
            // 搜索
            search() {
                this.getData();
            },
            //加载第几页
            handleCurrentChange(val) {
                this.page = val;
                this.getData();
            },
            // 全选
            handleCheckAllChange(val) {
                if (this.checkAll) {
                    this.$refs.multipleTable.toggleAllSelection();
                } else {
                    this.$refs.multipleTable.clearSelection();
                }
            },
            resetQuery() {
                this.filterData = {};
                this.page = 1;
                this.getData();
            },
            // 商品分类
            checkMedalType(e) {
                this.filterData.medalType = e;
                this.getData()
            },
            // 监听选择的内容
            handleSelectionChange(val) {
                this.checkAll = this.dataList.length === val.length
            },
            // 获取数据
            getData() {
                this.loading = true;
                medalRecordList({
                    ...this.filterData,
                    page: this.page - 1
                }).then(res => {
                    if (res.data.isSuccessful === "Y") {
                        const {
                            count,
                            records
                        } = res.data.data;
                        this.count = count;
                        this.dataList  = records;
                    }
                })
                .catch(err => {})
                .finally(() => {
                    if (this.loading) {
                        this.loading = false
                    }
                });
            },
        }
    }
</script>
<style lang="scss" scoped>
   
</style>
